﻿@model PaggerViewModel
@{
    string Act = Model.Act.ToString();
    int PageIdx = (int)Model.PageIdx;
    int PageCount = (int)Model.PageCount;
    int PageNice = PageIdx + 1;
}
<div class="pagger">
    @if (PageCount > 0)
    {
        <span>@(PageIdx <= 0 ? Html.Label("首页") : Html.ActionLink("首页", Act, new { ID = 0 + 1 }, new { pidx = 0 }))</span>
        <span>@(PageIdx <= 0 ? Html.Label("上一页") : Html.ActionLink("上一页", Act, new { ID = PageNice - 1 }, new { pidx = PageIdx - 1 }))</span>


        for (int i = Math.Max(PageIdx - 3, 0); i < Math.Min(PageIdx + 4, PageCount); i++)
        {
            if (i != PageIdx)
            {
        <span>@Html.ActionLink((i + 1).ToString(), Act, new { ID = (i + 1).ToString() }, new { pidx = i })
        </span>
            }
            else
            { 
        <span>[@((i + 1).ToString())]</span>
            }
        }


        <span>@(PageIdx >= (PageCount - 1) ? Html.Label("下一页") : Html.ActionLink("下一页", Act, new { ID = PageNice +1 }, new { pidx = PageIdx + 1 }))</span>
        <span>@(PageIdx >= (PageCount - 1) ? Html.Label("末页") : Html.ActionLink("末页", Act, new { ID = (PageCount).ToString() }, new { pidx = PageCount - 1 }))</span>

        <span>&nbsp;&nbsp;&nbsp;共 [@Model.ItemCount] 项内容</span>
    }
    else
    {
        <span>没有内容</span>
    }
</div>
<script type="text/javascript">
    $(function () {
        $(".pagger a").click(function () {
            var pidx = $(this).attr("pidx");
            $("#qspidx").val(pidx);
            $("#qssubmit").parents("form").first().submit();
            return false;
        });
    });
</script>
